﻿using System;
using System.Collections.Generic;
using System.Text;

using System.Xml;

namespace SDB2DM.Feature
{
    class Feature : JPGISXML, IFeature
    {
        public Feature(XmlDocument doc, XmlNode objectNode, 
            string featureName, string featureTag, string featrueId, string featurePrefix)
            : base(ref doc)
        {
            this.objectNode = objectNode;
            this.featureName = featureName;
            this.featureTag = featureTag;
            this.featureId = featureTag;
            this.featurePrefix = featurePrefix;
        }

        private XmlNode objectNode = null;
        protected XmlNode ObjectNode
        {
            get
            {
                return objectNode;
            }
        }

        #region IFeature メンバ

        private string featureName = String.Empty;
        public string FeatureName
        {
            get
            {
                return featureName;
            }
        }

        private string featureTag = String.Empty;
        public string FeatureTag
        {
            get
            {
                return featureTag;
            }
        }

        private string featureId = String.Empty;
        public string FeatureID
        {
            get
            {
                return featureId;
            }
        }

        private string featurePrefix = String.Empty;
        public string FeaturePrefix
        {
            get
            {
                return this.featurePrefix;
            }
        }

        private string visibilityTag = String.Empty;
        public string VisibilityTag
        {
            get
            {
                return Utility.APP_VISIBILITY_TAG;
            }
        }

        private string visibilityValue = String.Empty;
        public string VisibilityValue
        {
            get
            {
                return Utility.APP_VISIBILITY_VALUE;
            }
        }

        private string positionTag = String.Empty;
        public string PositionTag
        {
            get
            {
                return Utility.APP_POS_TAG;
            }
        }

        private string positionIdref = String.Empty;
        public string PositionIdref
        {
            get
            {
                return positionIdref;
            }
            set
            {
                positionIdref = value;
            }
        }

        protected void BuildXMLForAppSchema(XmlNode objectNode, string idName, string strFormat, int idx)
        {
            XmlNode featureNode = null;
            XmlNode visiNode = null;
            XmlNode posNode = null;

            featureNode = XMLDoc.CreateElement(
                Utility.CM_DOMAIN_TAG, FeatureTag, Utility.CM_SCHEMA_URI);
            visiNode = XMLDoc.CreateElement(VisibilityTag);
            posNode = XMLDoc.CreateElement(
                Utility.CM_DOMAIN_TAG, PositionTag, Utility.CM_SCHEMA_URI);

            (featureNode as XmlElement).SetAttribute(
                Utility.CM_ATTRIBUTE_ID_TAG, FeatureTag + String.Format(strFormat, idx));
            visiNode.InnerText = VisibilityValue;
            (posNode as XmlElement).SetAttribute(Utility.CM_ATTRIBUTE_IDREF_TAG, idName);

            objectNode.AppendChild(featureNode);
            featureNode.AppendChild(visiNode);
            featureNode.AppendChild(posNode);
        }

        public virtual void BuildApplicationData()
        { 
        }

        #endregion
    }
}
